package com.jianyun.jyzs.model;

import android.util.Log;

import com.jianyun.jyzs.bean.UpdataPwdBean;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.CustomCallback;
import com.jianyun.jyzs.http.RetrofitHelper;
import com.jianyun.jyzs.model.imdoel.IUpdatePhoneModel;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yangshijun on 2018/8/1.
 */

public class UpdataPhoneModel implements IUpdatePhoneModel {

    private static UpdataPhoneModel model;

    private UpdataPhoneModel() {
    }

    public static UpdataPhoneModel getInstance() {
        if (model == null) {
            model = new UpdataPhoneModel();
        }
        return model;
    }

    @Override
    public void updataPhone(String enterpriseCode, String userId, String mobilePhone, final OnUpdatePhoneListener onUpdatePhoneListener) {
        Api api = RetrofitHelper.builderErpHttp().create(Api.class);
        api.upPhone("UpdateMobile", enterpriseCode, userId, mobilePhone, "jyzs", "Android", "1.0.2")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<UpdataPwdBean>() {
                    @Override
                    protected void onResponse(UpdataPwdBean response) {
                        if (response.isResult()) {
                            onUpdatePhoneListener.onSuccess();
                        } else {
                            onUpdatePhoneListener.onException(response.getMessage());
                        }
                    }

                    @Override
                    protected void onException(String msg) {
                        onUpdatePhoneListener.onFailed();
                    }
                });
    }
}
